﻿<?php
class main {
	public function redirect($link) {
		echo "<script>window.location = '" . $link . "' </script>";
	}
	function dequy($parentid, $aCats, $sep = '', $cols = array()) {
		foreach ( $aCats as $v ) {
			if ($v ["cat_root"] == $parentid) {
				$cols [$v ["cat_id"]] ['cat_id'] = $v ["cat_id"];
				
				$cols [$v ["cat_id"]] ['cat_name'] = $sep . $v ["cat_name"];
				
				//$cols[$v["cat_id"]]['priority'] = $sep.$v["priority"];
				

				$cols = $this->dequy ( $v ["cat_id"], $aCats, $sep . "---- ", $cols );
			}
		}
		return $cols;
	}
	function upimg($file,$dir,$x="300"){
		$handle = new upload($file);
	  	if ($handle->uploaded) {
	      	$handle->image_resize         = true;
	      	$handle->image_x              = $x;
	      	$handle->image_ratio_y        = true;
	      	$handle->image_text            = 'hmh.com.vn';
			$handle->image_text_color      = '#0000FF';
			$handle->image_text_background = '#FFFFFF';
			$handle->image_text_position   = 'BR';
			$handle->image_text_padding_x  = 10;
			$handle->image_text_padding_y  = 2;			
	      	$handle->process($dir);
		    if ($handle->processed) {
		        return $handle->file_dst_name;		        
		    }
		    $handle->clean();
	  	} else {
	  		echo $handle->error;
	  	}
	}
	function imgnotext($file,$dir,$x="300"){
		$handle = new upload($file);
	  	if ($handle->uploaded) {
	      	$handle->image_resize         = true;
	      	$handle->image_x              = $x;
	      	$handle->image_ratio_y        = true;	
	      	$handle->process($dir);
		    if ($handle->processed) {
		        return $handle->file_dst_name;		        
		    }
		    $handle->clean();
	  	} else {
	  		echo $handle->error;
	  	}
	}
	function url_friend($str) {
		$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);
		$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
		$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
		$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);
		$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
		$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
		$str = preg_replace("/(đ)/", 'd', $str);
		$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);
		$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
		$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
		$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);
		$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
		$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
		$str = preg_replace("/(Đ)/", 'D', $str);
		$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
		$str = preg_replace("/(\:|\;|\`|\'|\"|\~|\!|\@|\#|\%|\^|\&|\*|\,|\/|\(|\)|\.)/", '', $str);
		$str = str_replace("\\", "", $str);
		$str = str_replace("$", "", $str);
		$str = str_replace(" ", "-", $str);
		$str = str_replace("--", "-", $str);
		$str = str_replace("---", "-", $str);
		$str = str_replace("----", "-", $str);
		$str = strtolower($str);
		return $str;
	}
}
$main = new main ();
?>